package cn.gok.demo3.controller;


import cn.gok.demo3.mapper.ClazzMapper;
import cn.gok.demo3.entity.Clazz;
import cn.gok.demo3.entity.Student;
import cn.gok.demo3.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xxxx
 * @since 2022-07-21
 */
@RestController
@RequestMapping("/clazz")
public class ClazzController {
    @Autowired
    private ClazzMapper clazzMapper;

    @RequestMapping("/findAllClazz")
    public List<Clazz> findAllClazz(){
        return clazzMapper.findAllClazz();
    }

    @RequestMapping("/findClazzById")
    public Clazz findClazzById(@RequestParam int cid){
        return clazzMapper.selectById(cid);
    }

    @RequestMapping("/findAll")
    public List<Map<Clazz,Student>> findAll(){
        return clazzMapper.findAll();
    }
    @RequestMapping("/addClazz")
    public int addClazz(@RequestBody Clazz clazz){
        return clazzMapper.insert(clazz);
    }

    @RequestMapping("/updateClazz")
    public int updateClazz(@RequestBody Clazz clazz){
        return clazzMapper.updateById(clazz);
    }

    @RequestMapping("/deleteById")
    public int deleteById(@RequestParam Long cid){
       return clazzMapper.deleteById(cid);
    }

    @RequestMapping("/deleteByIds")
    public int deleteByIds(@RequestBody List<Long> arr){
        return clazzMapper.deleteBatchIds(arr);
    }
}

